/**
 * Created by apple on 16/7/4.
 */
angular.module("starter.router", ['ionic','ionic-native-transitions'])
  .config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider,$provide,$sceDelegateProvider) {

    // $ionicConfigProvider.views.maxCache(0);
    $ionicConfigProvider.platform.ios.tabs.style('standard');
    $ionicConfigProvider.platform.ios.tabs.position('bottom');
    $ionicConfigProvider.platform.android.tabs.style('standard');
    $ionicConfigProvider.platform.android.tabs.position('bottom');

    $ionicConfigProvider.backButton.text("");
    $ionicConfigProvider.backButton.previousTitleText(false);

    $ionicConfigProvider.platform.ios.navBar.alignTitle('center');
    $ionicConfigProvider.platform.android.navBar.alignTitle('center');

    $ionicConfigProvider.platform.ios.backButton.previousTitleText(' ').icon('ion-android-arrow-back');
    $ionicConfigProvider.platform.android.backButton.previousTitleText(' ').icon('ion-android-arrow-back');

    $ionicConfigProvider.platform.ios.views.transition('android');
    $ionicConfigProvider.platform.android.views.transition('android');

    //$ionicConfigProvider.scrolling.jsScrolling(false);

    $ionicConfigProvider.views.swipeBackEnabled(false);
    $ionicConfigProvider.scrolling.jsScrolling(true);
    //$ionicConfigProvider.platform.ios.views.maxCache(10);
    // Ionic uses AngularUI Router which uses the concept of states
    // Learn more here: https://github.com/angular-ui/ui-router
    // Set up the various states which the app can be in.
    // Each state's controller can be found in controllers.js
    //$sceDelegateProvider.resourceUrlWhitelist(['.*']);
    $sceDelegateProvider.resourceUrlWhitelist([
      // Allow same origin resource loads.
      'self',
      // Allow loading from our assets domain.  Notice the difference between * and **.
      'http*://**'
    ]);

    $stateProvider

      //引导中间页
      .state("guideTemp",{
        url:'/guideTemp',
        templateUrl:'templates/guide/guideTemp.html',
        controller:"GuideTempCtrl"
      })

    //登录
      .state('login', {
        url: '/login',
        templateUrl: 'templates/login/login.html',
        controller: 'LoginCtrl'
      })

      // 重置密码
      .state('reset',{
        url:'/reset',
        templateUrl:'templates/login/resetPassword.html',
        controller:'ResetCtrl'
      })

      //主界面
      .state('tab', {
        url: '/tab',
        abstract: true,
        templateUrl: 'templates/tabs/tabs.html'
      })

      //航天分布式
      .state('tab.htjd',{
        url: '/htjd',
        views: {
          'tab-htjd':{
            templateUrl: 'templates/htjd/htjd.html',
            controller: 'HtjdCtrl'
          }
        }
      })

      .state('tab.htjd-doc',{
        url: '/htjd-doc',
        views: {
          'tab-htjd':{
            templateUrl: 'templates/htjd/htjd-doc.html',
            controller: 'HtjdDocCtrl'
          }
        },
        params:{args:{}}
      })

      .state('tab.htjd-more',{
        url: '/htjd-more',
        views: {
          'tab-htjd':{
            templateUrl: 'templates/htjd/htjd-more.html',
            controller: 'HtjdMoreCtrl'
          }
        },
        params:{args:{}}
      })

      // .state('tab.htjd',{
      //   url: '/htjd',
      //   views: {
      //     'tab-htjd':{
      //       templateUrl: 'templates/htjd/htjd.html',
      //       controller: 'HtjdCtrl'
      //     }
      //   },
      //   nativeTransitions: {
      //     type: "fade"
      //   }
      // })

      //项目档案
      .state('tab.project-track',{
        url: "/project-track",
        views: {
          'tab-project-track':{
            templateUrl: 'templates/project-track/project-track.html',
            controller: 'ProjectTrackCtrl'
          }
        },
        nativeTransitions: {
          type: "fade"
        }
      })

      //项目档案内容
      .state('tab.project-track-content',{
        url: "/project-track/project-track-content",
        cache: false,
        views: {
          'tab-project-track':{
            templateUrl: 'templates/project-track/project-track-content.html',
            controller: 'ProjectTrackContentCtrl'
          }
        },
        params:{args:{}}
      })

      .state('tab.project-log',{
        url: "/project-track/project-log",
        views: {
          'tab-project-track':{
            templateUrl: 'templates/project-track/project-log.html',
            controller: 'ProjectLogCtrl'
          }
        },
        params:{args:{}}
      })

      // 任务界面
      .state('tab.tasks', {
        url: '/tasks',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/tabs/tab-tasks.html',
            controller: 'TaskCtrl'
          }
        },
        nativeTransitions: {
          type: "fade"
        }
      })
      //二级页面
      //销售意向
      .state('tab.task-intention', {
        url: '/tasks/intention',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-intention-create.html',
            controller: 'TaskIntentionCreateCtrl'
          }
        },
        params:{args:{}}
      })

      //销售跟进信息
      .state('tab.task-follow', {
        url: '/tasks/follow',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-follow.html',
            controller: 'TaskFollowCtrl'
          }
        },
        params:{args:{},disable:''}
      })

      .state('tab.task-common-choice',{
        url: '/task/task-common-choice',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-common-choice.html',
            controller: 'CommonChoiceCtrl'

          }
        },
        params:{args:{}}
      })

      .state('tab.task-mutable-choice',{
        url: '/task/task-mutable-choice',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-mutable-choice.html',
            controller: 'MutableChoiceCtrl'

          }
        },
        params:{args:{}}
      })

      .state('tab.task-common-textarea',{
        url: '/task/task-common-textarea',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-common-textarea.html',
            controller: 'CommonTextareaCtrl'
          }
        },
        params: {args: {}}
      })

      .state('tab.task-common-choicePhoto', {
        url: '/task/task-common-choicePhoto',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-common-choicePhoto.html',
            controller: 'CommonChoicePhotoCtrl'
          }
        },
        params: {args: {}}
      })

      .state('tab.task-common-photo',{
        url: '/task/task-common-photo',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-common-photo.html',
            controller: 'CommonPhotoCtrl'
          }
        },
        params:{args:{},disable:false}
      })

      .state('tab.task-design-choice',{
        url: '/task/task-design-choice',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-design-choice.html',
            controller: 'DesignChoiceCtrl'
          }
        },
        params:{args:{}}
      })

      .state('tab.task-assigned-choice',{
        url: '/task/task-assigned-choice',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-assigned-choice.html',
            controller: 'AssignedChoiceCtrl'
          }
        },
        params:{args:{}}
      })

      // 勘察确认
      .state('tab.task-position-submit' ,{
        cache: false ,
        url: '/task/task-position-submit',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-design-map.html',
            controller: 'TaskDesignMapCtrl',
          }
        },
        params:{args:{},flag:{}}
      })

      .state('tab.task-survey',{
        url: '/tasks/survey',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-survey.html',
            controller: 'TaskSurveyCtrl'
          }
        },
        params:{args:{}}
      })

      .state('tab.task-design',{
        url: '/tasks/design/:taskId',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-design.html',
            controller: 'TaskDesignCtrl'
          }
        },
        params:{args:{}}
      })

      .state('tab.task-to-be-assigned',{
        url: '/tasks/to-be-assigned/:taskId',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-to-be-assigned.html',
            controller: 'TaskToBeAssignedCtrl'
          }
        },
        params:{args:{}}
      })

      .state('tab.task-design-autocal',{
        url: '/tasks/design-autocal/:taskId',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task-design/autocal.html',
            controller: 'AutocalCtrl'
          }
        },
        params:{args:{},wmInfo:{}}
      })

      .state('tab.task-design-choose-pack',{
        url: '/tasks/design-choose-pack/:taskId',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task-design/choose-pack.html',
            controller: 'ChoosePackCtrl'
          }
        }
      })

      /* 收货 */
      .state('tab.task-delivery', {
        url: '/tasks/delivery',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-delivery.html',
            controller: 'DeliveryCtrl'
          }
        },
        params: {args:{},doRefresh:{}}
      })

      /* 扫描列表 */
      .state('tab.task-delivery-scan',{
        url:'/tasks/delivery/scan',
        views: {
          'tab-tasks':{
            templateUrl: 'templates/task-delivery/scan.html',
            controller: 'DeliveryScanCtrl'
          }
        },
        params:{args:{},ctgy:{},type:{},NBQIndex:{},theFirstElementOfGFZJ:{},receivingDataForGFZJLength:{},project:{}}
      })

      /* 项目自查 */
      .state('tab.task-checkProject',{
        url: '/tasks/checkProject',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-checkProject.html',
            controller: 'CheckProjectCtrl'
          }
        },
        params:{args:{}}
      })
      /* 并网验收 */
      .state('tab.task-checkAndReceive',{
      url: '/tasks/checkAndReceive',
      views:{
        'tab-tasks':{
          templateUrl: 'templates/task/task-checkAndReveive.html',
          controller: 'CheckAndReceiveCtrl'
        }
      },
        params:{args:{},doRefresh:{}}
      })

      /* 进度报告 */
      .state('tab.task-progressReport',{
        url: '/tasks/progressReport',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-progressReport.html',
            controller: 'ProgressReportCtrl'
          }
        },
        params:{args:{},doRefresh:{}}
      })

      /* 合同签订 */
      .state('tab.task-contract-sign',{
        url: '/task/contractSign',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-contractSign.html',
            controller: 'ContractSignCtrl'
          }
        },
        params:{
          args:{
            project:{}
          }
        }
      })

      /* 方案整改 */
      .state('tab.task-correction',{
        url: '/task/correction',
        views: {
          'tab-tasks': {
            templateUrl: 'templates/task/task-correction.html',
            controller: 'CorrectionCtrl'
          }
        },
        params: {
          args:{
            project:{}
          }
        }
      })

      /* 工程量变更 */
      .state('tab.task-qutyChange',{
        url: '/task/qutyChange',
        views: {
          'tab-tasks':{
            templateUrl: 'templates/task/task-qutyChange.html',
            controller: 'QutyChangeCtrl'
          }
        },
        params: {
          args: {
            project: {},doRefresh:{}
          }
        }
      })

      .state('tab.chats', {
        url: '/chats',
        views: {
          'tab-chats': {
            templateUrl: 'templates/tab-chats.html',
            controller: 'ChatsCtrl'
          }
        }
      })
      .state('tab.chat-detail', {
        url: '/chats/:chatId',
        views: {
          'tab-chats': {
            templateUrl: 'templates/chat-detail.html',
            controller: 'ChatDetailCtrl'
          }
        }
      })

      // .state('tab.account', {
      //   url: '/account',
      //   views: {
      //     'tab-account': {
      //       templateUrl: 'templates/tab-account.html',
      //       controller: 'AccountCtrl'
      //     }
      //   }
      // })

      // 我的面板
      .state('tab.my', {
        url: '/my',
        views: {
          'tab-my': {
            templateUrl: 'templates/my/tab-my.html',
            controller: 'MyCtrl'
          }
        },
        nativeTransitions: {
          type: "fade"
        }
      })

      // 账号管理面板
      .state('tab.my-account', {
        url: '/my/account',
        views: {
          'tab-my': {
            templateUrl: 'templates/my/tab-my-account.html',
            controller: 'MyAccountCtrl'
          }
        }
      })

      // 修改手机号确认密码面板
      .state('tab.my-account-phone-password', {
        url: '/my/account/phone/password',
        views: {
          'tab-my': {
            templateUrl: 'templates/my/tab-my-account-phone-password.html',
            controller: 'MyAccountPhonePasswordCtrl'
          }
        }
      })

      // 修改手机号面板
      .state('tab.my-account-phone', {
        url: '/my/account/phone',
        views: {
          'tab-my': {
            templateUrl: 'templates/my/tab-my-account-phone.html',
            controller: 'MyAccountPhoneCtrl'
          }
        }
      })

      // 修改密码面板
      .state('tab.my-account-password', {
        url: '/my/account/password',
        views: {
          'tab-my': {
            templateUrl: 'templates/my/tab-my-account-password.html',
            controller: 'MyAccountPasswordCtrl'
          }
        }
      })

      // 我的设置面板
      .state('tab.my-settings', {
        url: '/my/settings',
        views: {
          'tab-my': {
            templateUrl: 'templates/my/tab-my-settings.html',
            controller: 'MySettingsCtrl'
          }
        }
      })

      //我的关于面板
      .state("tab.my-about",{
        url: "/my/about",
        views:{
          'tab-my':{
            templateUrl: "templates/my/tab-my-about.html",
          }
        }
      })

      //我的消息
      .state("tab.my-messages",{
        url: "/my/messages",
        views:{
          'tab-my':{
            templateUrl: "templates/my/tab-my-messages.html",
            controller: 'MyMessagesCtrl'
          }
        }
      })



    //$timeout(function(){
    //  $cordovaSplashscreen.hide();
    //  //获取缓存中的isFirstLoad来判断是否为第一次加载应用
    //  var isFirstLoad = $dfCache.getObject("isFirstLoad");
    //
    //  //判断isFirstLoad.flag的值，第一次加载为undefined，以后加载为false
    //  if (angular.isUndefined(isFirstLoad.flag) || isFirstLoad.flag){
    //
    //    //更改为false
    //    isFirstLoad.flag = false;
    //
    //    //加入缓存
    //    $dfCache.putObject("isFirstLoad",isFirstLoad);
    //
    //    console.log(isFirstLoad.flag);
    //    $urlRouterProvider.otherwise('/guidePage');
    //  }else{
    //    $urlRouterProvider.go("login");
    //  }
    //},500);

    // if none of the above states are matched, use this as the fallback
    // $urlRouterProvider.otherwise('/login');
    $urlRouterProvider.otherwise('/guideTemp');
  });
